﻿package framework 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * 层管理器
	 * @author cwin5
	 */
	public class LayerManager 
	{
		////////////////////////////////////////////////////////////////////////////////
		//	层
		////////////////////////////////////////////////////////////////////////////////
		private var _sceneLayer:Sprite = null;								// 房间层
		private var _gameLayer:Sprite = null;								// 游戏层	
		private var _topUI:Sprite = null;									// 顶
		private var _textTipsLayer:Sprite = null;                           // 文字提示层，不接收鼠标事件
		private var _gameAni:Sprite = null;									// 游戏动画
		
	
		////////////////////////////////////////////////////////////////////////////////
		/**
		 *  场景层
		 */
		////////////////////////////////////////////////////////////////////////////////
		public static const SCENELAYER:String = "sceneLayer";	
		public static const GAMELAYER:String = "gameLayer";
		public static const TOPUI:String = "topUI";
		public static const TIPSLAYER:String = "textTipsLayer";
		public static const GAMEANI:String = "gameAni";
		
		private var inACTIVATE:Boolean = true;
		////////////////////////////////////////////////////////////////////////////////
		// 层属性
		private const layerType:Array = [SCENELAYER, GAMELAYER, GAMEANI, TOPUI, TIPSLAYER];
		
		// 层数组
		private var _layerArr:Array = null;
		
		////////////////////////////////////////////////////////////////////////////////
		
		/**
		 * 构造
		 */
		public function LayerManager(single:Single)
		{
			
		}
		
		/**
		 * 初始化
		 */
		public function init():void
		{
			_layerArr = [];
			
			var main:Main = GlobalVar.main;
			
			for (var i:int = 0; i < layerType.length; i++)
			{
				var sprite:Sprite = new Sprite();
				var str:String = layerType[i];
				this["_" + str] = sprite;
				_layerArr.push(sprite);
				main.addChild(sprite);
				
				if (str != TOPUI)
				{
					sprite.mouseChildren = false;
					sprite.mouseEnabled = false;
				}
			}
			//_gameLayer.scrollRect = new Rectangle(0, 0, GameConfig.GAMEDISPLAYAREA.x, GameConfig.GAMEDISPLAYAREA.y);
			//_moveBgLayer.scrollRect = new Rectangle(0, 0, GameConfig.GAMEDISPLAYAREA.x, GameConfig.GAMEDISPLAYAREA.y);
			main.tabChildren = false;
			main.tabEnabled = false;
		}
		
		/**
		 * 增加对象到层
		 * @param	type 层的类型属性
		 * @param	displayObj	需要增加的对象s
		 */
		public function addToLayer(type:String , displayObj:DisplayObject):void
		{
			var sprite:Sprite = this["_" + type];
			sprite.addChild(displayObj);
		}
		
		/**
		 *  获取层次
		 * @param	type
		 * @return
		 */
		public function getLayer(type:String):Sprite
		{
			var sprite:Sprite = this["_" + type];
			return sprite;
		}
		
		
		/**
		 * 单例引用
		 */
		static public function get instance():LayerManager
		{
			if(_instance == null)
			{
				_instance = new LayerManager(new Single());
			}
			return _instance;
		}
		
		static private var _instance:LayerManager = null;
	}
}
class Single{}